﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="test_Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" href="css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/jquery.fancybox.js" type="text/javascript"></script>
<script src="js/jquery.message.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/fancybox.css" />
</head>
<body>
<form  id="form1" runat="server">
<table id="list"></table> 
<div id="pager"></div> 
</form>
<script language="javascript" type="text/javascript">
    $(document).ready(docReady);

function docReady() {
    var colNames = [];
    var colModel = [];
    if (!outputData || !outputData.columns) {
        return;
    }

    var columns = outputData.columns;
    for (var index = 0, len = columns.length; index < len; index++) {
        colNames.push(columns[index].title);
        colModel.push({ index: columns[index].key, name: columns[index].key, width: 80,
         align: 'center'});
    }

    $("#list").jqGrid({
        caption: outputData.caption,
        url: '../orders',
        datatype: "json",
        colNames: colNames,
        colModel: colModel,
        rowNum: 10,
        //rowList: [10, 20, 30],
        pager: '#pager',
        //sortname: 'id',
        autowidth: true,
        height: 300,
        viewrecords: true,
        multiselect: true,
        multiselectWidth: 25,
        sortable: false
        //sortorder: "asc"
    });

//    $.ajax({
//        url: "../orders",
//        data: "id=1",
//        type: "GET",
//        success: getDataSuccess
//    });
};

function getDataSuccess(dataStr) {
    if (!dataStr) {
        return;
    }

    var data = eval(dataStr);
    if (!data) {
        return;
    }

    var list = $("#list");
    for (var index = 0, len = data.length; index < len; index++) {
        convertDateItem(data[index]);
        //list.jqGrid("addRowData", index, data[index]);
    }
};

function convertDateItem(obj) {
    for (var item in obj) {
        var value = obj[item];
        if (typeof (value) != "string" || value.indexOf("/Date(") == -1 || value.indexOf(")/") == -1) {
            continue;
        }

        var date = convertDate(value);
        obj[item] = date;
    }
};

function convertDate(jsondate) {
    jsondate = jsondate.replace("/Date(", "").replace(")/", "");
    if (jsondate.indexOf("+") > 0) {
        jsondate = jsondate.substring(0, jsondate.indexOf("+"));
    }
    else if (jsondate.indexOf("-") > 0) {
        jsondate = jsondate.substring(0, jsondate.indexOf("-"));
    }

    return new Date(parseInt(jsondate, 10));
};

</script>
</body>
</html>
